#include <boost/interprocess/shared_memory_object.hpp>
#include <boost/interprocess/mapped_region.hpp>
#include <cstring>
#include <cstdlib>
#include <string>
#include <iostream>

using namespace boost::interprocess;

int main()
{
	shared_memory_object shm(open_only, "MySharedMemory", read_write);

	mapped_region region(shm, read_write);

	std::cout << std::endl << "Memoria antes accedida por programa 2" << std::endl;
	char *mem = static_cast<char*>(region.get_address());
	for (size_t i = 0; i < region.get_size(); ++i, ++mem)
	{
		std::cout << *mem << std::endl;
	}

	std::memset(region.get_address(), 3, region.get_size());
	std::cout << std::endl << "Memoria modificada por programa 2" << std::endl;
	char *mem2 = static_cast<char*>(region.get_address());
	for (size_t i = 0; i < region.get_size(); ++i, ++mem2)
	{
		std::cout << *mem2 << std::endl;
	}

	return 1;
}